
#include "TFSoundManager.h"

bool TFSoundManager::soundEnabled=true;
bool TFSoundManager::rumbleEnabled=true;
bool TFSoundManager::musicEnabled=true;
//sound effects
//RAW format, stored in codebase\TroopsAndFlags\data
#include "knock1.h"
#include "knock2.h"
#include "click1.h"
#include "click2.h"
#include "invalid.h"
#include "troopno.h"
#include "troophooh.h"
#include "blueok.h"
#include "redroger.h"

//music
//MOD format, stored in codebase\TroopsAndFlags\data
//#include "mig29.h"

HRESULT TFSoundManager::PlaySound(TFSound soundName)
{
	switch(soundName)
	{
		case SOUND_MENU_MOVE:
			if (rumbleEnabled == true)
			{
				TFSoundManager::Rumble(30,10);
			}
			if (soundEnabled == true)
			{
				PA_PlaySimpleSound(1, knock1);
			}
			break;
		case SOUND_MENU_SELECT:
			if (rumbleEnabled == true)
			{
				TFSoundManager::Rumble(15,3);
			}
			if (soundEnabled == true)
			{
				PA_PlaySimpleSound(1, knock2);
			}
			break;
        case SOUND_SELECT_PIECE:
            if (soundEnabled == true)
            {
                PA_PlaySimpleSound(1, click1);
            }
            break;
		case SOUND_PLACE_TROOP_RED:
            if (soundEnabled == true)
            {
                PA_PlaySimpleSound(1, redroger);
            }
            break;
        case SOUND_PLACE_TROOP_BLUE:
            if (soundEnabled == true)
            {
                PA_PlaySimpleSound(1, blueok);
            }
            break;
        case SOUND_KNOCK_TROOP_RED:
            if (soundEnabled == true)
            {
                PA_PlaySimpleSound(1, troophooh);
            }
            break;
        case SOUND_KNOCK_TROOP_BLUE:
            if (soundEnabled == true)
            {
                PA_PlaySimpleSound(1, troopno);
            }
            break;
        case SOUND_INVALID_MOVE:
            if (soundEnabled == true)
            {
                PA_PlaySimpleSound(1, click2);
            }
            break;
	}

	return S_OK;
}

HRESULT TFSoundManager::PlayMusic(TFMusic musicName)
{
	if (musicEnabled == false)
	{
		return E_FAIL;
	}
	switch(musicName)
	{
		case MUSIC_BACKGROUND_INTRO:
			//PA_PlayMod(mig29); 
			break;
	}

	return S_OK;
}


void TFSoundManager::Rumble(s16 time, s16 rumbleRate)
{
    //must be toggled between true/false to cause the rumble motor to move
    //The faster you toggle the harder it rumbles!
    bool rumbleMotorPos = true;
    for (s16 i=0; i < time; i++)
    {
        if (i % rumbleRate == 0)
        {
            rumbleMotorPos = ! rumbleMotorPos;
            setRumble(rumbleMotorPos);
            PA_WaitForVBL();
        }
    }
}

void TFSoundManager::setSoundEnabled(bool sound)
{
	soundEnabled = sound;
}

void TFSoundManager::setRumbleEnabled(bool rumble)
{
	rumbleEnabled=rumble;
}

void TFSoundManager::setMusicEnabled(bool music)
{
	musicEnabled=music;
}

bool TFSoundManager::isSoundEnabled()
{
	return soundEnabled;
}

bool TFSoundManager::isMusicEnabled()
{
	return musicEnabled;
}

bool TFSoundManager::isRumbleEnabled()
{
	return rumbleEnabled;
}
